<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="监控设备名称" prop="equipmentName">
        <el-input
          v-model="queryParams.equipmentName"
          placeholder="请输入监控设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="监控设备编码" prop="equipmentCode">
        <el-input
          v-model="queryParams.equipmentCode"
          placeholder="请输入监控设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="监控设备类型" prop="equipmentType">
        <template slot-scope="scope">
          <el-select v-model="queryParams.equipmentType" placeholder="设备类型" :onSelectionChange="handleQuery" clearable>
            <el-option v-for="dict in dict.type.platform_equipment_type" :key="dict.value" :label="dict.label"
                       :value="dict.value" />
          </el-select>
        </template>
      </el-form-item>
      <el-form-item label="仓位名称" prop="storeLocationName">
        <el-input
          v-model="queryParams.storeLocationName"
          placeholder="请输入仓位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓位编码" prop="storeLocationCode">
        <el-input
          v-model="queryParams.storeLocationCode"
          placeholder="请输入仓位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预警类型" prop="warningType" width="120">
        <template slot-scope="scope">
          <el-select v-model="queryParams.warningType" placeholder="预警类型" :onSelectionChange="handleQuery" clearable>
            <el-option v-for="dict in dict.type.platform_warning_type" :key="dict.value" :label="dict.label"
                       :value="dict.value" />
          </el-select>
        </template>
      </el-form-item>

      <el-form-item label="预警时间" prop="warningTimeRange">
        <div class="block">
          <el-date-picker v-model="queryParams.warningTimeRange" type="datetimerange"
                          format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                          align="right">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['platform:warningReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warningList" >
      <el-table-column label="预警ID" align="center" prop="warningId" />
      <el-table-column label="预警类型" width="120" align="center" prop="warningType" />
      <el-table-column label="预警内容" align="center" prop="warningContent" />
      <el-table-column label="监控设备名称"  width="100" align="center" prop="equipmentName" :show-overflow-tooltip="true"/>
      <el-table-column label="监控设备编码"  width="100" align="center" prop="equipmentCode" :show-overflow-tooltip="true"/>
      <el-table-column label="监控设备Ip"  width="100" align="center" prop="equipmentIp" />
      <el-table-column label="监控设备类型"  width="100" align="center" prop="equipmentType" :show-overflow-tooltip="true"/>
      <el-table-column label="仓位名称" align="center" prop="storeLocationName" :show-overflow-tooltip="true"/>
      <el-table-column label="仓位编码" align="center" prop="storeLocationCode" />
      <el-table-column label="初始水平角（球机）"  width="100" align="center" prop="pan" />
      <el-table-column label="初始垂直角（球机）"  width="100" align="center" prop="tilt" />
      <el-table-column label="缩放倍数" align="center" prop="zoom" />
      <el-table-column label="仓位状态" width="80" align="center" prop="storeLocationStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.platform_location_status" :value="scope.row.storeLocationStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
                     v-hasPermi="['platform:command:edit']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--查看预警台账详情对话框 -->
    <el-dialog title="预警台账详情" :close="cancelDetail" :visible.sync="viewCommandObj.open" width="800px" append-to-body>
      <div v-loading="viewCommandObj.loading">
        <el-form label-width="120px" v-if="!viewCommandObj.loading">
          <el-row>
            <el-col :span="12">
              <el-form-item label="仓库名称">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.equipment.storeName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="仓库编码" prop="storeCode" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.equipment.storeCode }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="仓位名称">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.location.storeLocationName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="仓位编码" prop="storeLocationCode" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.location.storeLocationCode }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="仓位货物数量">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.location.quantity }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="仓位状态" :show-overflow-tooltip="true">
                <dict-tag :options="dict.type.platform_location_status"
                          :value="this.viewCommandObj.data.location.storeLocationStatus" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="水平初始角">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.location.pan }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="初始垂直角">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.location.tilt }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="监控设备名称" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.equipment.equipmentName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="监控设备编码" prop="equipmentChannel" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.equipment.equipmentCode }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="监控设备IP" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.equipment.equipmentIp }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="监控设备类型" :show-overflow-tooltip="true">
                <dict-tag :options="dict.type.platform_equipment_type"
                          :value="this.viewCommandObj.data.equipment.equipmentType" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="预警内容">
              <el-input v-model="this.viewCommandObj.data.warningContent" type="textarea" placeholder="预警内容" disabled />
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="预警类型" >
                <dict-tag :options="dict.type.platform_warning_type" :value="this.viewCommandObj.data.warningType" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预警时间" :show-overflow-tooltip="true">
                {{ parseTime(this.viewCommandObj.data.warningTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="this.viewCommandObj.data.commandResult !== null">
            <el-col :span="12">
              <el-form-item label="指令类型" >
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.commandResult.commandTypeName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="指令内容" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.commandResult.commandContent }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="this.viewCommandObj.data.commandResult !== null">
            <el-col :span="12">
              <el-form-item label="指令执行内容" >
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.commandResult.content }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="指令执行状态" :show-overflow-tooltip="true">
                <span class="mx-1" size="large"> {{ this.viewCommandObj.data.commandResult.executionStatus }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="this.viewCommandObj.data.commandResult !== null">
            <el-col :span="12">
              <el-form-item label="指令执行开始时间" :show-overflow-tooltip="true">
                {{ parseTime(this.viewCommandObj.data.commandResult.executeStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="指令执行结束时间" :show-overflow-tooltip="true">
                {{ parseTime(this.viewCommandObj.data.commandResult.executeEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" v-if="!viewCommandObj.loading">
        <!-- <el-button icon="el-icon-s-promotion" v-if="this.viewCommandObj.data.executeCommandResult.executionStatus > 1"
          type="primary" @click="retrySendCommand">重试</el-button> -->
        <el-button @click="cancelDetail" icon="el-icon-back">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getWarningReport, listWarningReports} from "@/api/platform/warning"
import moment from 'moment';
export default {
  name: "WarningReport",
  dicts: ['platform_warning_type','platform_equipment_type','platform_location_status','platform_command_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预警报表表格数据
      warningList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipmentName: null,
        equipmentCode:null,
        equipmentType: null,
        storeLocationName: null,
        storeLocationCode: null,
        warningType: null,
        warningTime: null,
        warningTimeRange:null,
        warningStartTime:null,
        warningEndTime:null,
        warningId: null
      },
      // 表单参数
      form: {},
      // 查看时执行指令对象
      viewCommandObj: {
        open: false,
        item: null,
        loading: true,
        data: {
          location:{},
          equipment:{},
          commandResult:{},
          loading: true,
        }
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      if (Array.isArray(this.queryParams.warningTimeRange)) {
        this.queryParams.warningStartTime = moment(this.queryParams.warningTimeRange[0]).format('YYYY-MM-DD HH:mm:ss')
        this.queryParams.warningEndTime = moment(this.queryParams.warningTimeRange[1]).format('YYYY-MM-DD HH:mm:ss')
      }
      listWarningReports(this.queryParams).then(response => {
        this.warningList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        equipmentName: null,
        equipmentCode:null,
        equipmentType: null,
        storeLocationName: null,
        storeLocationCode: null,
        warningType: null,
        warningTime: null,
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.viewCommandObj.loading = true
      this.viewCommandObj.open = true
      // const queryParams = {
      //   warningId: row.warningId,
      // }
      getWarningReport(row.warningId).then(response => {
        this.viewCommandObj.data = response.data
        this.viewCommandObj.loading = false
      })
    },
    cancelDetail() {
      this.viewCommandObj.open = false
      this.viewCommandObj.loading = true
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('platform/warn-report/export', {
        ...this.queryParams
      }, `warningReport_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

